package com.oazon.common.util;

import java.util.UUID;

import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.provider.Settings.Secure;
import android.telephony.TelephonyManager;

public class DriveUUIDUtil {

	/**
	 * 得到设备<a href="http://www.it165.net/pro/ydad/" target="_blank"
	 * class="keylink">Android</a>ID，需要设备添加 Google账户
	 *
	 * @param context
	 * @return
	 */
	public static String getAndroidID(Context context) {
		String androidID = Secure.getString(context.getContentResolver(),
				Secure.ANDROID_ID);
		return androidID;
	}

	/**
	 * 得到设备IMEI值
	 *
	 * @param context
	 * @return
	 */
	public static String getIMEI(Context context) {
		TelephonyManager tm = (TelephonyManager) context
				.getSystemService(Context.TELEPHONY_SERVICE);
		return tm.getDeviceId();
	}

	/**
	 * 通过IMEI获得uuid
	 * @param context
	 * @return
	 */
	public static String getDriverUUID(Context context){
//		String uuid ="";
//		uuid = UUID.nameUUIDFromBytes(getIMEI(context).getBytes()).toString();
//		return uuid;
		return getMacAddress(context) + ":F";
		
	}
	
	/**
	 * 获取mac地址
	 * @param context
	 * @return
	 */
	public static String getMacAddress(Context context){
		WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
		WifiInfo info = wifi.getConnectionInfo();
		String address = info.getMacAddress().replace(":", "-").toUpperCase();
		return address;
	}
	
	/**
	 * 得到设备序列号
	 *
	 * @param context
	 * @return
	 */
	public static String getSimSerialNumber(Context context) {
		TelephonyManager tm = (TelephonyManager) context
				.getSystemService(Context.TELEPHONY_SERVICE);
		return tm.getSimSerialNumber();
	}

	/**
	 * 得到设备唯一识别码
	 *
	 * @param context
	 * @return
	 */
	public static String getUniqueNumber(Context context) {
		String androidID = getAndroidID(context);
		String imei = getIMEI(context);
		String simSerialNumber = getSimSerialNumber(context);
		UUID uuid = new UUID(androidID.hashCode(),
				((long) imei.hashCode() << 32) | simSerialNumber.hashCode());
		return uuid.toString();
	}
}
